package  ${packageName};

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ${import.entity.packageName}.${import.entity.className};
import ${import.dto.packageName}.${import.dto.className};
import ${import.udto.packageName}.${import.udto.className};
import ${import.service.packageName}.${import.service.className};
import user.zc.core.util.PageParam;
import user.zc.core.util.R;

@Slf4j
@RestController
@RequestMapping("/${className}")
public class ${className}{
    @Autowired
    private ${import.service.className} ${import.service.beanName};


    @ApiOperation(value = "创建${tableComment}",notes="创建${tableComment}")
    @PostMapping(value="/create",produces = "application/json")
    public R create(@RequestBody @Validated ${import.dto.className} ${import.dto.beanName}){
        try {
            return R.success(${import.service.beanName}.add(${import.dto.beanName}.trans(${import.entity.className}.class)));
        } catch (Exception e) {
            return R.failure(e.getMessage());
        }
    }


    @ApiOperation(value = "修改${tableComment}",notes="修改${tableComment}")
    @PutMapping(value="/update",produces = "application/json")
    public R update(@RequestBody @Validated ${import.udto.className} ${import.udto.beanName}){
        try {
            return R.success(${import.service.beanName}.update(${import.udto.beanName}.trans(${import.entity.className}.class)));
        } catch (Exception e) {
            return R.failure(e.getMessage());
        }
    }

    @ApiOperation(value = "删除${tableComment}",notes="删除${tableComment}")
    @DeleteMapping(value="/delete/{id}",produces = "application/json")
    public R delete(@PathVariable Long id){
        return R.success(${import.service.beanName}.delete(id));
    }

    @ApiOperation(value = "查找所有${tableComment}",notes="查找所有${tableComment}")
    @GetMapping(value="/findList",produces = "application/json")
    public R findList(@RequestParam(value = "size") int size,
                      @RequestParam(value = "page") int page){
        return R.success(${import.service.beanName}.findPage( PageParam.builder(size,page).build()));
    }

    @ApiOperation(value = "查找${tableComment}",notes="查找${tableComment}")
    @GetMapping(value="/get/{id}",produces = "application/json")
    public R findList(@PathVariable Long id){
        return R.success(${import.service.beanName}.get(id));
    }
}
